package org.cnc.app;

import java.awt.BorderLayout;
import java.awt.KeyboardFocusManager;
import java.rmi.RemoteException;
import java.rmi.server.ServerNotActiveException;

import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import org.cnc.core.DetailModel;
import org.cnc.gui.ModelDrawer;
import org.cnc.rmi.interfaces.ModelDrawerInterface;
import org.cnc.rmi.interfaces.RmiServer;
import org.jvnet.substance.skin.SubstanceRavenGraphiteGlassLookAndFeel;

public class Drawer{

	public class DrawerModule extends ServerModule<Server>
	{		
		public DrawerModule() throws RemoteException,
				ServerNotActiveException
		{
			super( new Server("drawer", 3101) );
			
			modelDrawer = new ModelDrawer();
			
			this.frame.add(modelDrawer, BorderLayout.CENTER );
		}

		
	}
	
	@SuppressWarnings("serial")
	class Server extends RmiServer
	implements ModelDrawerInterface 
	{
		public Server( String name, int port )
				throws RemoteException {
			super( name, port );
		}

		@Override
		public void update( DetailModel model, int x, int y, int z)
		{
			System.out.println( "Data received: t\tModel: " + model.toString() + "\tx: " + x + ", y: " + y + ", z: " + z);

			modelDrawer.update(model, x, y, z);
		}
	}
	
	public static void main( String args[] )
	{
		SwingUtilities.invokeLater ( new Runnable()
		{
			public void run ()
			{
				try
				{
					Drawer application = new Drawer();
					
				    UIManager.setLookAndFeel (new SubstanceRavenGraphiteGlassLookAndFeel()  );
				    
				    DrawerModule drawerModule = application.new DrawerModule();
				    
				    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(drawerModule);
				}
				catch ( Exception e )
				{
				    e.printStackTrace();
				}
			}
		} );
	}
	
	private ModelDrawer modelDrawer;
}